<template>
	<!-- 登录 -->
	<!-- <view class="content" > -->
		<!--   滚动通知  -->
		<!-- <view>  
			<u-notice-bar :text="text1"  color="#9e9e9e"></u-notice-bar>
		</view>
		<view class="avatorWrapper">
			<view class="avator">
				<image class="img" src="http://121.5.128.59:9000/picture/7f3a87eb908a415c8a8e9524f3416bb0.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="form">
			<view class="inputWrapper" v-if="showName">
				<input class="input" type="text" value="" v-model="userName" placeholder="请输入用户名"   />	
			</view> -->
			<!-- <view class="loginBtn" @click="loginbt">
				<text class="btnValue"  >一键登录</text>
			</view> -->
			<!-- <view class="forgotBtn">
				<text @click="loginBtn">微信授权登录 >></text>
			</view> -->
		<!-- </view> -->
		
		
	<!-- </view> -->
	<view class="content">
			<view class="bg"></view>
			<view class="bg2"></view>
			<view class="tips">
				<text class="title">登录(login)</text>
				<text class="subtitle">欢迎再次回来~</text>
				<text class="subtitle">Welcome back again~</text>
			</view>
			<view class="form-box">
				<!-- 账号 -->
				<view class="input-box" v-if="showName">
					<image class="left"
						src="https://cdnjson.com/images/2023/09/26/7dba7e2a1725fc58b4a9506a0c976331.png">
					</image>
					<input placeholder="请输入用户名"  v-model="userName" />
					<!-- <image class="right"
						src="/static/箭头.png">
					</image> -->
				</view>
				
				<view class="btn" @click="loginbt">一键登录(One-click login)</view>
				<!-- <view class="other">
					<text>找回密码</text>
					<text style="color:#00c6fc;">快速注册</text>
				</view> -->
			</view>
			<!-- 判断用户是否已经同意隐私政策，如果未同意则显示弹窗 -->
			<privacy-popup ref="privacyComponent" position="center" ></privacy-popup>
		</view>
</template>
 
<script>
	// import privacy from '@/components/privacy.vue';
	import privacyComponent from '@/components/privacy-popup/privacy-popup.vue';
	let data;
	export default {
		components: {
		    privacyComponent,
		  },
		data() {
			return {
				// privacyShow: false, // 用户是否已同意隐私政策的标志位
				userName:'',
				pwd: '',
				showName: false,
				text1: '注意：一个用户只能绑定一个角色，绑定后不能更改，如需重新绑定请联系管理员'
			}
		},
		onReady() {},
		onLoad(option) {
			data = JSON.parse(decodeURIComponent(option.data));
			console.log(data,"登录类型==")
		},
		methods: {
			loginbt(){
				console.log("点击登录按钮***   登录类型  *****",data,"--------",this.userName,this.pwd)
					switch (data){
						case '管理员':
							var that = this;
							uni.showLoading({ // 展示加载框
								title: '登录加载中',
							});
							uni.getUserProfile({     	//获取到用户信息
								desc: '登录后数据',
								success: async (obj) => {
									console.log('obj', obj);
									that.nickName = obj.userInfo.nickName      //用户名
									that.avatarUrl = obj.userInfo.avatarUrl   //用户头像
									// 调用 action ，请求登录接口
									uni.login({
										provider: 'weixin',
										success: (res) => {
											that.code = res.code;
											//请求登录接口
											if (res.errMsg == 'login:ok') {
												uni.request({
													url: 'https://www.smacaftersales.com:443/wxLogin',
													method: 'POST',
													data:{
														code: that.code,
														userName: this.userName,
													},
													success: (res) => {
														console.log(res,"-----oppppppp------")
														switch (res.data.msg){
															case '已绑定':
																console.log("管理员已绑定",);
																uni.setStorageSync('identify',0)
																uni.setStorageSync("userid",res.data.data.userId)
																uni.setStorageSync("nickname",res.data.data.nickName)
																uni.setStorageSync("adminOpenid",res.data.data.openid);
																uni.showLoading({ 
																	title: '正在登录请稍后',
																});
																this.timerIntv = setTimeout( () => {
																	uni.reLaunch({
																		url: '/pages/adminVue/orderView'
																	})
																}, 1000)
																break;
															case 'openid绑定成功':
																this.userName = ''
																uni.setStorageSync('identify',0)
																uni.setStorageSync("userid",res.data.data.userId)
																uni.setStorageSync("nickname",res.data.data.nickName)
																uni.setStorageSync("adminOpenid",res.data.data.openid);
																uni.showLoading({
																	title: '微信绑定成功，正在跳转',
																});
																this.timerIntv = setTimeout( () => {
																	uni.reLaunch({
																		url: '/pages/adminVue/orderView'
																	})
																}, 2000)
																
																console.log("openid绑定成功")
																break;
															case '账号为空':
																this.showName = true
																uni.showToast({
																	title: '请填写账号',
																	duration: 2000,
																	icon: 'none'
																})
																console.log("账号为空")
																break;
															case '账号不正确':
																uni.showToast({
																	title: '请核实账号是否正确',
																	duration: 1500,
																	icon: 'none'
																})
																break;
															case '账号权限不足，请换过账号登录':
																console.log("-----   账号权限 不足  --------")
																uni.showToast({
																	title: '账号权限不足,请换账号登录',
																	duration:2000,
																	icon:'none',
																})
																break;
															case '用户没有分配角色':
																uni.showToast({
																	title: '用户无分配角色，请联系管理员',
																	duration:2000,
																	icon:'error'
																})
																break; 
															case '账号已绑定微信':
																uni.showToast({
																	title: '该账户已被绑定!',
																	duration:2000,
																	icon: 'none'
																})
																break;
															default:
																break;
														}
														
													}
												})
											}
										},
									});
								},
								fail: () => {
									uni.showToast({
										title: '授权已取消',
										icon: 'error',
										mask: true,
									});
								},
								complete: () => {
									// 隐藏loading
									uni.hideLoading();
								},
							});
							break;
						case '售后人员':
							console.log("售后人员")
							var that = this;
							uni.showLoading({ // 展示加载框
								title: '登录加载中',
							});
							uni.getUserProfile({ //获取到用户信息
								desc: '登录后数据',
								success: async (obj) => {
									console.log('obj', obj);
									that.nickName = obj.userInfo.nickName      //用户名
									that.avatarUrl = obj.userInfo.avatarUrl   //用户头像
									// 调用 action ，请求登录接口
									uni.login({
										provider: 'weixin',
										success: (res) => {
											that.code = res.code;
											//请求登录接口
											if (res.errMsg == 'login:ok') {
												uni.request({
													url: 'https://www.smacaftersales.com:443/afterSaleLogin',
													method: 'POST',
													data:{
														code: that.code,
														userName: this.userName,
													},
													success: (res) => {
														console.log(res)
														switch (res.data.msg){
															case '已绑定':
																console.log("已绑定------------")
																uni.setStorageSync('identify',1)
																uni.setStorageSync("userid",res.data.data.userId)
																uni.setStorageSync("nickname",res.data.data.nickName)
																uni.setStorageSync("openid",res.data.data.openid)
																
																console.log(uni.getStorageSync('userid'),"---- 11111-----")	
																uni.$on('send', () => {
																		uni.$emit("workOrderNumberMsg", res.data.data)
																		// 传参 或 传递一个对象 uni.$emit("cardMsg", {})
																		
																		console.log('发送数据' + res.data.data);
																	})
																
																uni.showLoading({ 
																	title: '正在登录请稍后',
																});
																this.timerIntv = setTimeout( () => {
																	uni.reLaunch({
																		url: '/pages/afterSaleVue/index/index'
																	})
																}, 1000)
																break;
															case 'openid绑定成功':
																this.userName = ''
																uni.setStorageSync('identify',1)
																uni.setStorageSync("userid",res.data.data.userId)
																uni.setStorageSync("nickname",res.data.data.nickName)
																uni.showLoading({
																	title: '微信绑定成功，正在跳转',
																});
																uni.$on('send', () => {
																		uni.$emit("workOrderNumberMsg", res.data.data)
																		// 传参 或 传递一个对象 uni.$emit("cardMsg", {})
																		
																		console.log('发送数据' + res.data.data);
																	})
																this.timerIntv = setTimeout( () => {
																	uni.reLaunch({
																		url: '/pages/afterSaleVue/index/index'
																	})
																}, 2000)
																
																console.log("openid绑定成功")
																break;
															case '账号为空':
																this.showName = true
																uni.showToast({
																	title: '请填写账号',
																	duration: 2000,
																	icon: 'none'
																})
																console.log("账号为空")
																break;
															case '账号不正确':
																uni.showToast({
																	title: '请核实账号是否正确',
																	duration: 1500,
																	icon: 'none'
																})
																break;
															case '账号权限不足，请换过账号登录':
																console.log("-----   账号权限 不足  --------")
																uni.showToast({
																	title: '账号权限不足,请换账号登录',
																	duration:2000,
																	icon:'none',
																})
																break;
															case '用户没有分配角色':
																
																uni.showToast({
																	title: '用户无分配角色，请联系管理员',
																	duration:2000,
																	icon:'error'
																})
																break;
															case '账号已绑定微信':
																uni.showToast({
																	title: '该账户已被绑定',
																	duration:2000,
																	icon: 'none'
																})
																break;
															default:
																break;
														}
														
													}
												})
											}
										},
									});
								},
								fail: () => {
									uni.showToast({
										title: '授权已取消',
										icon: 'error',
										mask: true,
									});
								},
								complete: () => {
									// 隐藏loading
									uni.hideLoading();
								},
							});
						
							break;
						case '技术人员审批':
							console.log("-----  技术人员审批  -----")
							var that = this;
							uni.showLoading({ // 展示加载框
								title: '登录加载中',
							});
							uni.getUserProfile({ //获取到用户信息
								desc: '登录后数据',
								success: async (obj) => {
									console.log('obj', obj);
									that.nickName = obj.userInfo.nickName      //用户名
									that.avatarUrl = obj.userInfo.avatarUrl   //用户头像
									// 调用 action ，请求登录接口
									uni.login({
										provider: 'weixin',
										success: (res) => {
											that.code = res.code;
											//请求登录接口
											if (res.errMsg == 'login:ok') {
												uni.request({
													url: 'https://www.smacaftersales.com:443/technicalApproveLogin',
													method: 'POST',
													data:{
														code: that.code,
														userName: this.userName,
													},
													success: (res) => {
														console.log(res,"-----------")
														switch (res.data.msg){
															case '已绑定':
																console.log("技术人员已绑定")
																uni.setStorageSync("userid",res.data.data.userId)
																uni.showLoading({ 
																	title: '正在登录请稍后',
																});
																this.timerIntv = setTimeout( () => {
																	uni.reLaunch({
																		url: '/pages/index/technicalApproveVue/technicalApproveList'
																	})
																}, 1000)
																break;
															case 'openid绑定成功':
																this.userName = ''
																uni.setStorageSync("userid",res.data.data.userId)
																uni.showLoading({
																	title: '微信绑定成功，正在跳转',
																});
																this.timerIntv = setTimeout( () => {
																	uni.reLaunch({
																		url: '/pages/index/technicalApproveVue/technicalApproveList'
																	})
																}, 2000)
																
																console.log("openid绑定成功")
																break;
															case '账号为空':
																this.showName = true
																uni.showToast({
																	title: '请填写账号',
																	duration: 2000,
																	icon: 'none'
																})
																console.log("账号为空")
																break;
															case '账号不正确':
																uni.showToast({
																	title: '请核实账号是否正确',
																	duration: 1500,
																	icon: 'none'
																})
																break;
															case '账号权限不足，请换过账号登录':
																console.log("-----   账号权限 不足  --------")
																uni.showToast({
																	title: '账号权限不足,请换账号登录',
																	duration:2000,
																	icon:'none',
																})
																break;
															case '用户没有分配角色':
																uni.showToast({
																	title: '用户无分配角色，请联系管理员',
																	duration:2000,
																	icon:'error'
																})
																break; 
															case '账号已绑定微信':
																uni.showToast({
																	title: '该账户已被绑定!',
																	duration:2000,
																	icon: 'none'
																})
																break;
															default:
																break;
														}
														
													}
												})
											}
										},
									});
								},
								fail: () => {
									uni.showToast({
										title: '授权已取消',
										icon: 'error',
										mask: true,
									});
								},
								complete: () => {
									// 隐藏loading
									uni.hideLoading();
								},
							});
							
							break;
						default:
							break;
					}
			},
			// loginBtn(){
			// }
			
		}
	}
</script>
 
<style lang="scss">
	/* .content {
		background: #377EB4;
		width: 100vw;
		height: 100vh;
	}
	.avatorWrapper{
		height: 30vh;
		width: 100vw;
		display: flex;
		justify-content: center;
		align-items: flex-end;
	}
	.avator{
		width: 280upx;
		height: 260upx;
		overflow: hidden;
	}
	.avator .img{
		width: 100%;
		display: block; 
		margin: 0px auto; 
		border-radius: 50%;
	}
	.form{
		padding: 0 100upx;
		margin-top: 20px;
	}
	.inputWrapper{
		width: 100%;
		height: 80upx;
		background: white;
		border-radius: 20px;
		box-sizing: border-box;
		padding: 0 20px;
		margin-top: 25px;
	}
	.inputWrapper .input{
		width: 100%;
		height: 100%;
		text-align: center;
		font-size: 15px;
	}
	.loginBtn{
		width: 100%;
		height: 80upx;
		background: #77B307;
		border-radius: 50upx;
		margin-top: 50px;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.loginBtn .btnValue{
		color: white;
	}
	.forgotBtn{
		text-align: center;
		color: #52a5f7;
		font-size: 15px;
		margin-top: 20px;
	} */
	
	.content {
			width: 100vw;
			height: 100vh;
			background-color: #ffffff;
	
	.tips {
		padding-top: 200rpx;
		padding-left: 80rpx;
		display: flex;
		flex-direction: column;

		.title {
			line-height: 70rpx;
			font-weight: bold;
			font-size: 50rpx;
		}

		.subtitle {
			line-height: 70rpx;
			font-size: 35rpx;
			font-weight: bold;
			color: #b0b0b1;
		}

	}

	.bg {
		position: fixed;
		top: -250rpx;
		right: -250rpx;
		width: 600rpx;
		height: 600rpx;
		border-radius: 100%;
		background-color: #00baef;
		z-index: 2
	}

	.bg2 {
		position: fixed;
		top: -150rpx;
		right: -300rpx;
		width: 600rpx;
		height: 600rpx;
		border-radius: 100%;
		background-color: #ade8f9;
		z-index: 1;
	}

	.form-box {
		padding-top: 180rpx;
		padding-left: 70rpx;
		width: 610rpx;

		.input-box {
			margin: 40rpx 0;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			height: 100rpx;
			background-color: #f5f5f5;
			border-radius: 100rpx;
			width: 100%;

			input {
				flex: 1;
				height: 100%;
				font-size: 30rpx;
			}
			.left {
				padding: 0 35rpx;
				width: 35rpx;
				height: 35rpx;
			}
			.right {
				padding: 0 30rpx;
				width: 40rpx;
				height: 40rpx;
			}
		}

		.btn {
			margin-top: 10px;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: 100rpx;
			border-radius: 100rpx;
			color: #FFFFFF;
			background: linear-gradient(to right, #00c6fc, #9adcf1);
		}

		.other {
			display: flex;
			justify-content: space-between;

			text {
				line-height: 80rpx;
				font-size: 28rpx;
			}
		}
	}
}
	
	
</style>